//
//  WebServiceManager.h
//  eGiftr
//
//  Created by Phien Tram on 9/3/13.
//  Copyright (c) 2013 eGiftr. All rights reserved.
//

#import <Foundation/Foundation.h>

@protocol WebServiceManagerDelegate;

@interface WebServiceManager : NSObject

@property (nonatomic, assign) id<WebServiceManagerDelegate> delegate;

@property (nonatomic, strong) NSURLConnection *connection;
@property (nonatomic, strong) NSMutableData *receivedData;
@property (nonatomic, strong, readonly) NSString *serviceName;
@property (nonatomic, strong, readonly) NSString *method;
@property (nonatomic, strong, readonly) NSDictionary *inputData;

//output
@property (nonatomic, retain) id result;

- (id)initWithData:(NSDictionary *)data serviceName:(NSString *)serviceName method:(NSString *)method;

- (void)request;
- (void)cancelRequest;

// subclass implementation
- (NSString *)URL;
- (NSMutableURLRequest *)createConnectionURLRequest;
- (BOOL)parse:(NSString **)error code:(NSInteger *)code;

@end


@protocol WebServiceManagerDelegate <NSObject>

@optional
//for caching operators
- (void)webServiewManagerBeforeParsingData:(WebServiceManager *)manager data:(NSData *)data;


- (void)webServiceManagerFinishGetData:(WebServiceManager *)manager error:(NSError *)error;

@end
